#include <iostream>
#include<cstdio> 
using namespace std;
int n,m;
int printa()
{
}

int main()
{	
	cin >> n >> m;
	int i,j;
	int a[n][m]={0};
	for(i=0;i<n;i++)
	{
		printf("\n");
		for(j=0;j<m;j++)
		{
			cin >> a[i][j];
		}
	}
	
	for(i=1;i<n+2;i++)
	{
		printf("\n");
		for(j=1;j<m+2;j++)
		{
			if(a[i][j]==1)
			{
				a[i][j]=9;	
				cout <<  a[i][j] << " ";
			}
			else if(a[i][j]==0)
			{
				int count=printa();
				a[i][j]=count;
				cout << count << " ";
			}
			
		}
	}
	return 0;
}
